package projectodedalo.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import projectodedalo.excepcion.DAOExcepcion;
import projectodedalo.negocio.GestionAsesorIdea;
import projectodedalo.negocio.GestionIdea;
import projectodedalo.negocio.GestionUsuario;



/**
 * Servlet implementation class ApruebaIdeaServlet
 */
@WebServlet("/ApruebaIdeaServlet")
public class ApruebaIdeaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ApruebaIdeaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String idIdea = request.getParameter("idIdea");
		String idAsesor = request.getParameter("idAsesor");
		String idAccion = request.getParameter("accion");
		
		System.out.println("ApruebaIdeaServlet doPost:" + idIdea + " " + idAsesor + " " + idAccion);
		
		GestionIdea negIdea = new GestionIdea();		
		GestionAsesorIdea negEvalua = new GestionAsesorIdea();
		try {
			int i = negIdea.apruebaRechazaIdea(idIdea, idAccion);
			System.out.println("ApruebaIdeaServlet doPost I :" + i);

			if (idAccion.equals("APROBADA")) {  // Aprobar Idea -> Asigna Asesor
				int j=negEvalua.insertar(idIdea,idAsesor);
			}
			
//			request.setAttribute("LISTA", resultado);
			System.out.println("ApruebaIdeaServlet doPost llama a buscarideasservlet");
			response.sendRedirect(request.getContextPath()	+ "/BuscarIdeasServlet");
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}

}
